/* GJJoy.hh -- Módulo de controle do joystick
 *
 * Copyright (C) 2008, Diogo F. S. Ramos <diogo.ramos@usp.br>
 * GEAR - Grupo de Estudos Avançados em Robótica
 * <http://www.sel.eesc.usp.br/gear>
 *
 * This file is part of GEARJoystick.
 * 
 * GEARJoystick is free software: you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation, version 3 of the
 * License.
 * 
 * GEARJoystick is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see
 * <http://www.gnu.org/licenses/>.
 */

#ifndef GJJOY_HH_
#define GJJOY_HH_

#include <string>

#include "CommLineArgs.hh"
#include "GMRobot.hh"

#define JS_EVENT_BUTTON         0x01
#define JS_EVENT_AXIS           0x02
#define JS_EVENT_INIT           0x80

enum command_type
{
    NONE = -1,
    ROBOT_SET_VEL,
    ROBOT_KICK_STRONG,
    ROBOT_KICK_WEAK,
    ROBOT_DRIBBLE
};

typedef struct js_event js_event;

struct js_event
{
    unsigned int time;
    short value;
    unsigned char type;
    unsigned char number;
};

class GJJoy{
    GMRobot * robot_;
    int joystick_fd_;

    std::string joystick_path_;
    int server_port_;
    std::string server_addr_;
    std::string robot_end_;
    int robot_id_;

    float vx_;
    float vy_;
    float va_;

    int dribble_;

    enum command_type comtype_;

    struct js_event jse_;

	void dribble();
    void connectToMedula();
public:
    GJJoy();
    ~GJJoy();
    void Init( CommLineArgs line_args );
    int readJoystickEvent();
    void processEvent();
    void sendCommandToMedula();

};

#endif
